function [logic, intCorrelation, corrSum1] = computeIntCorrelation( num,nORr ,distance ,expCorr )
% compute int_correlation and logic matrix about neighbor
% "sort and find" way to acquire nearest nc neighbors  
% when topological == 0 , nORr means the visible distance.
global topological
sortDis = sort(distance);
logic = false(num,num);

    for i = 1 : num
        if topological == 1
            for j = 2 : nORr + 1 % do not contain itself !
            logic(:,i) = logic(:,i) | ( sortDis(j,i)==distance(:,i) );
            end
        elseif topological ==0
            logic(:,i) = logic(:,i) | ( distance(:,i)< nORr );
        else
            error('"topological" is not defined!')
        end
    end
    corrSum1 = zeros(1,num);
    for i = 1:num
        corr = expCorr(:,i);
        logi = logic(:,i);
        corrSum1(i) = sum(corr(logi)) ./ sum(logic(:,i)); % a row vector
    end
    intCorrelation = sum( corrSum1 ) / num;

end
